package com.alex.renju.renju.controller;

import com.alex.renju.renju.service.WebSocketServer;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

/**
 * @Author: Alex
 * @Description: 对弈
 * @Date: 2021/9/25
 */
@RestController
public class PlayController {

    @RequestMapping("/push/{toUserId}")
    public ResponseEntity<String> pushToWeb(String message, @PathVariable String toUserId) throws IOException {
        WebSocketServer.sendInfo(message, toUserId);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

    @RequestMapping("/userIsServer")
    public boolean userIsServer(String user) {
        return WebSocketServer.userIsServer(user);
    }


    @RequestMapping("/userIdListIsServer")
    public boolean userIdListIsServer(String user) {
        return WebSocketServer.userIdListIsServer(user);
    }

    @RequestMapping("/addOnLineUser")
    public void addOnLineUser(String userId) {
        WebSocketServer.addOnLineUser(userId);
    }

}
